<template>
	<view class="user-center">
		<view class="user">
			<image src="/static/logo.png" @click="handleLink"></image>
			<view class="username" v-if="user">
				{{user.userName}}
				<view class="role" v-if="user">
					{{user.role}}
				</view>
			</view>

		</view>
		<view class="menus">
			<view class="item" @click="handleLink('/pages/menu/menu')">
				<text class="iconfont icon-taocanjilu"></text>
				套餐管理
			</view>
			<view class="item" @click="handleLink('/pages/order/order')">
				币种管理
			</view>
			<view class="item" @click="handleLink('/pages/my/pages/setmenu')">
				支付管理
			</view>
			<view class="item" @click="handleLink('/pages/my/pages/setmenu')">
				订单管理
			</view>
			<view class="item" @click="handleLink('/pages/my/pages/setmenu')">
				报障管理
			</view>
			<view class="item" @click="handleLink('/pages/my/pages/setmenu')">
				常见问题
			</view>
		</view>
		<button @click="handleLogout"  type="warn" rond>退出</button>

	</view>
</template>

<script>
	import store from '../../store';
	import storage from '../../utils/storage';
	import {
		logoff
	} from '../../api/user';

	export default {
		data() {
			return {
				user: storage.get('user')
			};
		},

		onShow() {
			console.log(this.user, 'user')

		},
		methods: {
			handleLogout() {
				uni.redirectTo({
					url: '/pages/login/login'
				})
			},
			handleLink(url) {
				const app = getApp()
				if (app.globalData.$checkLogin()) {
					uni.navigateTo({
						url:url
					})
				}
			},
			handleDelUserAccout() {
				const app = getApp()
				if (app.globalData.$checkLogin()) {
					uni.showModal({
						title: '提示',
						content: '确定注销此账号？',
						success: async (res) => {
							console.log(res)
							if (res.confirm) {
								const result = await logoff({})
								console.log(result)
								if (!result.status) {
									uni.showToast({
										title: '注销成功',
										icon: 'success'
									})
									store.commit('CLEAR_USER', null)
								}
							}
						}
					})
				}
			},
			handleClick() {
				const app = getApp()
				console.log(app.globalData.$checkLogin())
			}
		},

	}
</script>

<style lang="scss" scoped>
	.user {
		width: 100%;
		height: 300rpx;
		background-color: #e98f36;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		image {
			border-radius: 50%;
			width: 100rpx;
			height: 100rpx;
		}

		.username {
			font-size: 30rpx;
			font-weight: bold;
			color: #fff;
			margin-top: 20rpx;
			display: flex;
			.role{
				font-size: 20rpx;
				margin-left: 20rpx;
				position: relative;
				top: 10rpx;
			}
		}
	}

	.menus {
		padding: 25rpx;

		.item {
			height: 80rpx;
			line-height: 80rpx;
			color: #5b5b5b;
			font-size: 26rpx;
			overflow: hidden;
			padding: 0 10rpx;
			border-bottom: 1px solid #e6e6e6;
		}
	}
	button{
		margin: 0 20rpx;
	}
</style>